// register
let [register, phone, psw, tip1] = [
    $("#btn_register"), $("#phone"), $("#psw"), $(".tip1")
];
class Register{
    constructor(){}
    init(register, phone, psw, tip1){
        this.register = register;
        this.phone = phone;
        this.psw = psw;
        this.tip1 = tip1;
        this.loading = false;
        this.bindEvent();
    }
    bindEvent(){
        this.register.click(this.sub.bind(this));
    }
    sub(){
        if(this.loading) return false;
        var name = this.phone.val();      
        var reg = /^1[^210]\d{9}$/;
        if(!reg.test(name)){
            this.tip1.html("手机号格式不正确！");
            return false;
        }else{
            this.tip1.html("OK！");
        }
        var password =  this.psw.val();
        this.loading = true;
        
        this.register.attr("disabled",true);
        this.register.html("loading...");
        xhrPost("http://10.9.65.230/interface/register.php",{
            name,
            password
        })
        .then((res)=>{
            console.log(res);   
            this.loading = false;
            this.register.attr("disabled",false);
            this.register.html("注册");
            window.location.href = 'http://localhost:8080/login.html';                                 
        
        })
    }
}
var r = new Register();
r.init(register, phone, psw, tip1);